package com.fili.gui.components.date_time;

import javax.swing.*;
import java.awt.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 29, 2006
 * Time: 2:21:16 PM
 */
public class DatePopupPanel extends JPanel
{
    private JPanel pnlTop;
    private JPanel pnlCenter;

    private String[] weekDays=new String[]{"Lu","Ma","Mi","Jo","Vi","Sa","Du"};

    public DatePopupPanel()
    {
        setPreferredSize(new Dimension(200, 150));
        setLayout(new BorderLayout());
        pnlTop = new JPanel();
        add(pnlTop, BorderLayout.NORTH);

        pnlCenter = new JPanel();
        add(pnlCenter, BorderLayout.CENTER);
        setupDate(new Date());
    }

    private void setupDate(Date date)
    {
        pnlCenter.removeAll();
        pnlCenter.setLayout(new GridLayout());

        Calendar cal = Calendar.getInstance(new Locale("RO", "RO"));
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        pnlCenter.setLayout(new GridLayout(0, 7));

        cal.set(Calendar.DAY_OF_MONTH,1);
        cal.set(Calendar.MONTH,Calendar.FEBRUARY);

        int n = cal.get(Calendar.DAY_OF_WEEK);
        if (n == Calendar.SUNDAY)
            n = 6;
        else n-=2;
       
        for (int i=0;i<n;i++)
            pnlCenter.add(new JLabel(""));
        
        for (int i=0;i<cal.getActualMaximum(Calendar.DAY_OF_MONTH);i++)
            pnlCenter.add(new DayLabel(""+(i+1), false, (i%7)==0));
    }
}
